﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using imaginecup.util;
using Microsoft.Xna.Framework;
using Imaginecup.sprite.rotate;
using Imaginecup.util.resourceMan;
using Imaginecup.shareData;

namespace Imaginecup.sprite
{
    public class RotateSprite : ISprite
    {
        private IRotateInfo m_RotateInfo; 

        private static Texture2D m_texture = null;

        public RotateSprite()
        {
            if (m_texture == null)
                CreateLineTexture(GraphicShareData.GetShareData().GetGraphicDevice());
        }


        public void SetRotateInfo( IRotateInfo rotateInfo )
        {
            m_RotateInfo = rotateInfo;
        }


        // 라인을 그리기 위해, 1x1 짜리 하얀색 pixel 텍스쳐를 만듬.
        static private void CreateLineTexture(GraphicsDevice device)
        {
            m_texture = new Texture2D(device, 1, 1, false, SurfaceFormat.Color);
            Color[] pixels = new Color[1];
            pixels[0] = Color.White;
            m_texture.SetData<Color>(pixels);
        }

        public void Draw(SpriteBatch spriteBatch, EntityInfo entityInfo)
        {
         //   Texture2D texture = ResourceMan.GetResourceMan().GetTexture(m_TextureName);

            float distance = m_RotateInfo.GetLength();
            float angle = m_RotateInfo.GetAngle();
                        
            spriteBatch.Begin();
            spriteBatch.Draw(m_texture, entityInfo.GetEntityCenter(), null, Color.White, angle, Vector2.Zero,
                new Vector2(distance, 1), SpriteEffects.None, 0);
 
            spriteBatch.End();
        }

        public void Release()
        {

        }

    }
}
